package org.helldorado.companybuilder;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import android.content.Context;
import android.media.MediaPlayer;
import android.provider.Settings;


public class ModelList {
	public List<Model> getList() {
		return m_list;
	}
	public Map<Integer, Model> getHashMap() {
		return m_hashMap;
	}
	private static ModelList s_modelList = null;
	private List<Model> m_list = null;
	private Map<Integer, Model> m_hashMap = null;
	private static Context s_ctx = null;
	
	public static ModelList getInstance(Context ctx) {
		Context applicationContext = ctx.getApplicationContext();
		if (s_ctx == null || s_ctx != applicationContext) {
			s_ctx = applicationContext;
			try {
				s_modelList = new ModelList(applicationContext);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}		
		return s_modelList;
	}

	private ModelList(Context ctx) throws InterruptedException
	{
		m_hashMap = ModelXmlPullParser.getModelsFromFile(ctx);
		m_list = new ArrayList<Model>(m_hashMap.values());
//		MediaPlayer player = MediaPlayer.create(ctx,
//			    Settings.System.DEFAULT_RINGTONE_URI);
//			player.start();
//			Thread.sleep(2000);
//			player.stop();
	}
}
